<template>
  <div class="login-container">
    <div class="title-container" style="margin-top: 15vh;">
      <h3 class="title">注&nbsp;册</h3>
    </div>
    <div style="position: relative;margin: auto;width: 500px;">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名" prop="name">
          <el-input type="name" v-model="ruleForm.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pwd">
          <el-input type="password" v-model="ruleForm.pwd" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="checkPass">
          <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="公司名称" prop="companyName">
          <el-input type="companyName" v-model="ruleForm.companyName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="公司编码" prop="companyCode">
          <el-input type="companyCode" v-model="ruleForm.companyCode" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="+86手机号" prop="phone">
          <el-input type="phone" v-model="ruleForm.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="请输入验证码" prop="code">
          <el-input type="code" v-model="ruleForm.code" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="submitForm('ruleForm')">注册</el-button>
      <el-button type="primary" @click="resetForm('ruleForm')">重置</el-button>
    </div>
  </div>
</template>
  
<script>
import { register } from '@/api/user';
export default {
  data() {

    return {
      ruleForm: {
        name: '',
        pwd: '',
        checkPass: '',
        companyName: '',
        companyCode: '',
        phone: ''
      },
      rules: {
        name: [
          { required: true, message: '用户名不能为空', trigger: 'blur' }
        ],
        pwd: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ],
        checkPass: [
          { required: true, message: '确认密码不能为空', trigger: 'blur' }
        ],
        companyName: [
          { required: true, message: '公司名不能为空', trigger: 'blur' }
        ],
        companyCode: [
          { required: true, message: '公司邮编不能为空', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(forName) {
      this.$refs[forName].validate((valid) => {
        if (valid) {
          register(this.ruleForm).then((res) => {
            if (res.code == 0) {
              this.$message({
                type: "success",
                message: res.msg
              }),
                this.$router.push({ path: "/login" })
            } else {
              this.$message({
                type: "error",
                message: res.msg
              })
            }
          })
        } else {
          this.$message.error("缺少必要信息，无法注册！")
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}

</script>
  
  
<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #283443;
$light_gray: #fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }

  .el-form-item__label {
    color: #ffff;
    margin-left: 20px;
  }
}
</style>
  
<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: #fff;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
  